package com.mongo.controller;

import com.mongo.pojo.MongoDb;
import com.mongo.pojo.MybatisPlus;
import com.mongo.service.impl.DbServiceImpl;
import com.mongo.service.impl.MybatisPlusServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DbController {

    @Autowired
    private MybatisPlusServiceImpl mybatisPlusService;

    @Autowired
    private DbServiceImpl dbService;

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public void findAllMybatis() {
        List<MybatisPlus> mybatisList = mybatisPlusService.findAll();
//        System.out.println(mybatisList.size());
//        for (MybatisPlus mybatis : mybatisList) {
//            System.out.println(mybatis.getVerId());
//        }
    }

    @RequestMapping(value = "/save", method = RequestMethod.GET)
    public void save() {
       dbService.save(null);
    }

    @RequestMapping(value = "/mongo", method = RequestMethod.GET)
    public void findAllMongo() {
        List<MongoDb> mongoDbs = dbService.find();
        for (MongoDb mongoDb : mongoDbs) {
            System.out.println(mongoDb.get_id() + "    "+mongoDb.getA2());
        }
    }

    @RequestMapping(value = "/mongoByIdList", method = RequestMethod.GET)
    public void mongoByName() {
        List<MongoDb> mongoDbs = dbService.findByIdList();
        for (MongoDb mongoDb : mongoDbs) {
            System.out.println(mongoDb.get_id() + "    "+mongoDb.getA2());
        }
    }


    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public void delete() {
        dbService.delete();
    }

    @RequestMapping(value = "/update", method = RequestMethod.GET)
    public void update() {
        dbService.update();
    }
}
